import  GlobalPersonaDao from './GlobalPersonaDao.js'
let global_persona_dao=new GlobalPersonaDao()
class GlobalPersona{
	constructor(){
        this.records=[]
    }

    async getSportRecordsByDate(start_date,end_date){
        let list=await  global_persona_dao.getSportRecordsByDate(start_date,end_date)
        this.records=list
    }
    getDailyTimeDistributionData(){
        let option_data=[
            {value: 0, name: '6:00～8:00'},
            {value: 0, name: '8:00～11:00'},
            {value: 0, name: '11:00～14:00'},
            {value: 0, name: '14:00～16:00'},
            {value: 0, name: '17:00～19:00'},
            {value: 0, name: '19:00～21:00'},
            {value: 0, name: '21:00～0:00'},
            {value: 0, name: '0:00～6:00'},
        ]
        for(let i=0; i<this.records.length; i++){
            let time=this.records[i].start_time
            let t=new Date(time)
            let t2=t.split(" ")
            t2=t2[4].split(":")
            let hour=parseInt(t2[0])
            if(hour>=6&&hour<8){
                option_data[0]++
            }else if(hour>=8&&hour<11){
                option_data[1]++
            }else if(hour>=11&&hour<14){
                option_data[2]++
            }
        }
        let option={
            title: {
                text: '一天中不同时间段的运动记录分布',
                left: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            series: [
                {
                    name: '运动记录',
                    type: 'pie',
                    roseType: 'area',
                    data: [
                        {value: 453, name: '6:00～8:00'},
                        {value: 71, name: '8:00～11:00'},
                        {value: 132, name: '11:00～14:00'},
                        {value: 84, name: '14:00～16:00'},
                        {value: 355, name: '16:00～19:00'},
                        {value: 222, name: '19:00～21:00'},
                        {value: 38, name: '21:00～0:00'},
                        {value: 5, name: '0:00～6:00'},
                    ],
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        },
                        normal:{ 
                            label:{ 
                                show: true, 
                                formatter: '{b} : {c} ({d}%)' 
                            }, 
                            labelLine :{show:true} 
                        } 
                    }
                }
            ]
          }
        return option
    }
    getWeatherDistributionData(){
        let option={
            title: {
                text: '运动时天气情况分布',
                left: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            series: [
                {
                    name: '天气情况',
                    type: 'pie',
                    roseType: 'area',
                    data: [
                        {value: 451, name: '晴朗'},
                        {value: 421, name: '阴'},
                        {value: 463, name: '多云'},
                        {value: 211, name: '小雨'},
                        {value: 23, name: '中雨'},
                        {value: 33, name: '暴雨'},
                        {value: 0, name: '小雪'},
                        {value: 0, name: '大雪'},
                        {value: 0, name: '冰雹'},
                    ],
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        },
                        normal:{ 
                            label:{ 
                                show: true, 
                                formatter: '{b} : {c} ({d}%)' 
                            }, 
                            labelLine :{show:true} 
                        } 
                    }
                }
            ]
          }
        return option
    }
    getLocationDistributionData(){
        var data = [
            {name: '金华', value: 157},
       ];
       var geoCoordMap = {
           '金华':[119.64,29.12]
       };
       
       var convertData = function (data) {
           var res = [];
           for (var i = 0; i < data.length; i++) {
               var geoCoord = geoCoordMap[data[i].name];
               if (geoCoord) {
                   res.push({
                       name: data[i].name,
                       value: geoCoord.concat(data[i].value)
                   });
               }
           }
           return res;
       };
       
       let option = {};
       return option
    }

    getComfortLevelDistributionData(){
        let option={
            title: {
                text: '运动时综合舒适度指标分布',
                left: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            series: [
                {
                    name: '运适宜度',
                    type: 'pie',
                    roseType: 'area',
                    data: [
                        {value: 451, name: '舒适'},
                        {value: 323, name: '较舒适'},
                        {value: 111, name: '不舒适'},
                        {value: 13, name: '极不舒适'},
                    ],
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        },
                        normal:{ 
                            label:{ 
                                show: true, 
                                formatter: '{b} : {c} ({d}%)' 
                            }, 
                            labelLine :{show:true} 
                        } 
                    }
                }
            ]
          }
        return option
    }
    getSportDurationDistributionData(){
        let option={
            title: { text: '运动持续时间分布情况' },
            tooltip: {},
            xAxis: {
                data: ["0～0.5","0.5～1","1～2","2以上"]
            },
            yAxis: {},
            series: [{
                name: '小时',
                type: 'bar',
                data: [16042, 18031, 6144, 1653]
            }]
        }
        return option
    }

    getSportTypeDistributionData(){
        let option = {
            title: {
                text: '不同运动类型总量对比',
                left: 'center'
            },
        
        
            series: [
                {
                    name: '运动计数',
                    type: 'pie',
                    radius: '50%',
                    data: [
                        {value: 1048, name: '跳绳'},
                        {value: 1735, name: '跑步'},
                        {value: 580, name: '仰卧起坐'},
                    ],
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        return option
    }

}

export default  GlobalPersona;